<body>
<pre id=preOnerror>FAIL: onerror was not called.</pre>
<pre id=console></pre>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + '\n'));
}

var hadError = false;
function error(message)
{
    hadError = true;
    log("FAIL: " + message);
}

function checkResponse()
{
    if (req.responseText.length) {
        error("responseText is not empty");
        if (window.testRunner)
            testRunner.notifyDone()
    }
}

function stealResponse()
{
    document.body.removeChild(document.getElementById('preOnerror'));

    req.open("GET", "http://127.0.0.1:8000/xmlhttprequest/resources/zero-length.xml");
    req.send();
    req.onreadystatechange = checkResponse;
    setTimeout(function() {
        checkResponse();
        if (!hadError)
            log("PASS");
        if (window.testRunner)
            testRunner.notifyDone()
    }, 100);
}

var req = new XMLHttpRequest;
req.open("GET", "http://localhost:8000/xmlhttprequest/resources/reply.xml", false);
try {
    req.send(null);
    error("send did not raise an exception");
} catch (ex) {
    stealResponse();
}
</script>
</body>
